package com.zz.ecommerce.declareManage.importB2CDeclareTax.personalDeclMgnQDc;

import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import com.zz.ecommerce.common.bean.qdc.db.TDeclformHeadQdc;
import com.zz.ecommerce.common.bean.qdc.db.TOrderHeadQdc;
import com.zz.ecommerce.common.constants.CommonConstants;
import com.zz.ecommerce.common.constants.DictConstants;
import com.zz.ecommerce.common.constants.TableConstants;
import com.zz.ecommerce.declareManage.common.dao.TDeclformHeadQdcDao;
import com.zz.ecommerce.declareManage.common.service.QdcOrderService;
import com.zz.ecommerce.utils.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * 进口B2C申报Controller
 * <p/>
 * Created by zhangguowei on 2016/3/28.
 */
@Controller
@RequestMapping("/importB2CTax/personalDeclQdc")
@Scope("prototype")
public class PersonalDeclareTaxQdcController {

    @Autowired
    private TDeclformHeadQdcDao tDeclformHeadQdcDao;

    @Autowired
    private QdcOrderService orderService;

    /**
     * 申报清单管理
     *
     * @return
     */
    @RequestMapping(value = "declarationForm", method = {RequestMethod.GET})
    public String declarationForm() {
        return "declareManage/importB2CDeclareTax/personalDeclQdc/declaration_form";
    }

    /**
     * 查询申报清单管理列表
     *
     * @param tDeclformHeadQdc
     * @param request
     * @return
     */
    @RequestMapping("/queryDeclareList")
    @ResponseBody
    public GridResult queryDeclareList(TDeclformHeadQdc tDeclformHeadQdc, GridRequest request, HttpSession session) {
        tDeclformHeadQdc.setIeFlag(CommonConstants.I_FALG);
        tDeclformHeadQdc.setTradeMode(CommonConstants.B2C_TAX);
        tDeclformHeadQdc.setOrgId(SessionUtil.getOrganizationId(session));
        tDeclformHeadQdc.setBusinessType(DictConstants.B2C);
        tDeclformHeadQdc.setReturnFlag(CommonConstants.ZERO);
        return new GridResult(tDeclformHeadQdcDao.page(TableConstants.T_DECLFORM_HEAD_QDC, tDeclformHeadQdc, request.getStart(), request.getEnd(), request.getSortOrder()), request, tDeclformHeadQdcDao.count(TableConstants.T_DECLFORM_HEAD_QDC, tDeclformHeadQdc));
    }

    @RequestMapping(value = "generateDeclaration", method = {RequestMethod.GET})
    public String generateDeclaration() {
        return "declareManage/importB2CDeclareTax/personalDeclQdc/generateDeclare/index";
    }

    @RequestMapping("/generateDeclareList")
    @ResponseBody
    public GridResult generateDeclareList(TOrderHeadQdc orderHead, GridRequest request, HttpSession session) {
//        orderHead.setOperId(SessionUtil.getOperator(session));
        orderHead.setOrgId(SessionUtil.getOrganizationId(session));
        orderHead.setIeFlag(DictConstants.IMPORT);
        orderHead.setBusinessType(DictConstants.B2C);
        orderHead.setTradeMode(DictConstants.TRADE_MODE_TAX);
        orderHead.setIfCreate("0");
        return orderService.queryOrderList(request, orderHead);
    }
}
